var a = require("../../../@babel/runtime/helpers/defineProperty"), t = getApp();

Page({
    data: {
        info: {},
        activeRole: "",
        activeName: 0,
        titleArr: [ "全部", "未结算", "已结算" ],
        dataList: [],
        isLoadMore: !0,
        networkLoading: !1
    },
    onLoad: function(a) {
        this.init();
    },
    init: function() {
        var a = [];
        this.data.titleArr.forEach(function(t, e) {
            a.push({
                isLoadMore: !0,
                page: 1,
                total_page: 0,
                list: []
            });
        }), this.setData({
            dataList: a,
            isLoadMore: !0
        }), this.getData();
    },
    getData: function() {
        var e = this;
        this.setData({
            networkLoading: !0
        });
        var i = t.getNetAddresss("plugin.merchant-meeting.frontend.index.bonus-info");
        t._getNetWork({
            url: i,
            data: {},
            success: function(t) {
                var i, s = t.data;
                1 == s.result ? (wx.setNavigationBarTitle({
                    title: s.data.plugin_name
                }), e.setData((i = {
                    networkLoading: !1,
                    info: s.data,
                    activeRole: s.data.lecturer ? 1 : 2
                }, a(i, "dataList[0].isLoadMore", !0), a(i, "dataList[0].total_page", s.data.bonusStatistic.bonusList.last_page), 
                a(i, "dataList[0].list", s.data.bonusStatistic.bonusList.data), i))) : wx.showToast({
                    title: s.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    changeRole: function(a) {
        this.setData({
            activeRole: a.detail.name
        });
        var t = [];
        this.data.titleArr.forEach(function(a, e) {
            t.push({
                isLoadMore: !0,
                page: 1,
                total_page: 0,
                list: []
            });
        }), this.setData({
            dataList: t,
            activeName: 0
        }), this.handleClick();
    },
    tabClick: function(a) {
        this.setData({
            activeName: a.detail.index
        }), this.handleClick();
    },
    handleClick: function(e) {
        this.setData({
            networkLoading: !0
        });
        var i = this;
        if (this.data.dataList[i.data.activeName].list.length > 0) i.data.isLoadMore = this.data.dataList[i.data.activeName].isLoadMore; else {
            var s = t.getNetAddresss("plugin.merchant-meeting.frontend.index.bonus-statistic");
            t._getNetWork({
                url: s,
                data: {
                    page: 1,
                    business_type: i.data.activeRole,
                    status: i.data.activeName - 1
                },
                success: function(t) {
                    var e, s = t.data;
                    1 == s.result ? i.setData((a(e = {
                        networkLoading: !1,
                        isLoadMore: !0
                    }, "dataList[" + i.data.activeName + "].isLoadMore", !0), a(e, "dataList[" + i.data.activeName + "].total_page", s.data.bonusList.last_page), 
                    a(e, "dataList[" + i.data.activeName + "].list", s.data.bonusList.data), e)) : wx.showToast({
                        title: s.msg,
                        icon: "none",
                        duration: 1e3
                    });
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    },
    _getMoreData: function() {
        var e = this;
        if (this.setData(a({}, "dataList[" + e.data.activeName + "].isLoadMore", !1)), !(this.data.dataList[this.data.activeName].page >= this.data.dataList[this.data.activeName].total_page)) {
            this.data.dataList[this.data.activeName].page = this.data.dataList[this.data.activeName].page + 1;
            var i = t.getNetAddresss("plugin.merchant-meeting.frontend.index.bonus-statistic");
            i += "&page=" + this.data.dataList[this.data.activeName].page, t._getNetWork({
                url: i,
                data: {
                    business_type: e.data.activeRole,
                    status: e.data.activeName - 1
                },
                success: function(t) {
                    var i = t.data;
                    if (1 == i.result) {
                        var s, o = i.data.bonusList.data;
                        e.setData((a(s = {}, "dataList[" + e.data.activeName + "].isLoadMore", !0), a(s, "dataList[" + e.data.activeName + "].list", e.data.dataList[e.data.activeName].list.concat(o.data)), 
                        s));
                    } else {
                        var n;
                        e.setData((a(n = {}, "dataList[" + e.data.activeName + "].isLoadMore", !1), a(n, "dataList[" + e.data.activeName + "].page", e.data.dataList[e.data.activeName].page - 1), 
                        n));
                    }
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.dataList[this.data.activeName].isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {}
});